package com.sensetime.jv.config;

import com.sensetime.jv.util.JsonUtils;
import feign.codec.Decoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

@Configuration
public class FeignConfig {



    @Bean
    public Decoder feignDecoder() {
        // 创建默认的 SpringDecoder
        ObjectFactory<HttpMessageConverters> objectFactory = () ->
            new HttpMessageConverters(new MappingJackson2HttpMessageConverter(JsonUtils.objectMapper));
        SpringDecoder springDecoder = new SpringDecoder(objectFactory);
        
        // 使用自定义解码器包装
        return new ReturnWrapperDecoder(springDecoder, JsonUtils.objectMapper);
    }
}